//
//  FriendCell.swift
//  chenChat
//
//  Created by chen on 16/2/20.
//  Copyright © 2016年 chen. All rights reserved.
//

import UIKit

class FriendCell: UITableViewCell {

    var cellBackgroundView: UIView
    var avatar: UIImageView
    var nameLabel: UILabel
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        self.cellBackgroundView = UIView(frame: CGRect(x: 0, y: 1, width: UIScreen.mainScreen().bounds.width, height: 55))
        self.cellBackgroundView.backgroundColor = UIColor.clearColor()
        
        self.avatar = UIImageView(frame: CGRectMake(5, 5, 45, 45))
        self.avatar.image = UIImage(named: "icon01.jpg")
        self.nameLabel = UILabel()
        self.nameLabel.frame = CGRectMake(55, 0, UIScreen.mainScreen().bounds.width - 55, 55)
        self.nameLabel.text = "chen"
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.cellBackgroundView.addSubview(self.avatar)
        self.cellBackgroundView.addSubview(self.nameLabel)
        
        self.addSubview(cellBackgroundView)
        
        self.backgroundColor = UIColor.clearColor()
        //阴影的颜色
        self.cellBackgroundView.layer.shadowColor = UIColor.blackColor().CGColor
        //阴影的位移方向
        self.cellBackgroundView.layer.shadowOffset = CGSizeMake(0, 2)
        //阴影的透明度
        self.cellBackgroundView.layer.shadowOpacity = 0.8
        //阴影的路径，self.bounds环绕view的周边
        self.cellBackgroundView.layer.shadowPath = CGPathCreateWithRect(self.bounds, nil)
    }
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    class func reuseIdentifier() -> String {
        return "friendCell"
    }
    class func heightForCell() -> CGFloat {
        return 56
    }
    func setFriendCell(user: UserInfo){
        if user.name?.isEmpty == true {
            self.nameLabel.text = "SomeOne"
            self.cellBackgroundView.backgroundColor = UIColor.magentaColor()
        }else{
            self.nameLabel.text = user.name
        }
        self.cellBackgroundView.backgroundColor = UIColor.grayColor()
    }

}
